News All Tests
Current file: /home/estudydev/workspace/MSP09/web/news/tests/class.mediawikiinfo.inc.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 13
10.58 %10.58%
10.58% 11 / 104
 
MediaWikiInfo
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 13
1.06 %1.06%
1.06% 1 / 94
 public function MediaWikiInfo($id, $image = NULL)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 4
 public function encryptPassword($userid, $password)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 1
 public function getWikiUserData($wikiUserName)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 3
 public function createNewWikiUser($login, $password, $email, $realname, $usergroup)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 34
 public function getRealName()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 1
 public function checkForUser()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public function getUserLogin()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 1
 public function insertNewUser()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public function removeUser($userID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 20
 public function updateLogin($oldLogin, $newLogin, $password)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 15
 public function createLogoffLogin($login)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 8
 public function showOptionsDialog($hiddenVars)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 1
 public function optionsHandler($event)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 1


       1                 : <?php                                                                                                                                                                                                                                                 
       2                 :                                                                                                                                                                                                                                                       
       3                 : /*--------------------------------------------------------------------------+                                                                                                                                                                         
       4                 : This file is part of eStudy                                                                                                                                                                                                                           
       5                 : externaltools/classes/class.mediawikiinfo.inc.php                                                                                                                                                                                                     
       6                 : - Modulgruppe:  ExternalTools                                                                                                                                                                                                                         
       7                 : - Beschreibung:                                                                                                                                                                                                                                       
       8                 : - Version:      1.0 13/10/05                                                                                                                                                                                                                          
       9                 : - Autor(en):    Christian Gerhardt <case42@gmx.net>                                                                                                                                                                                                   
      10                 : +---------------------------------------------------------------------------+                                                                                                                                                                         
      11                 : This program is free software; you can redistribute it and/or                                                                                                                                                                                         
      12                 : modify it under the terms of the GNU General Public License                                                                                                                                                                                           
      13                 : as published by the Free Software Foundation; either version 2                                                                                                                                                                                        
      14                 : of the License, or any later version.                                                                                                                                                                                                                 
      15                 : +---------------------------------------------------------------------------+                                                                                                                                                                         
      16                 : This program is distributed in the hope that it will be useful,                                                                                                                                                                                       
      17                 : but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                                                                                                                                        
      18                 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                                                                                                                                                         
      19                 : GNU General Public License for more details.                                                                                                                                                                                                          
      20                 : You should have received a copy of the GNU General Public License                                                                                                                                                                                     
      21                 : along with this program; if not, write to the Free Software                                                                                                                                                                                           
      22                 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                                                                                                                                                           
      23                 : +--------------------------------------------------------------------------*/                                                                                                                                                                         
      24                 : /**                                                                                                                                                                                                                                                   
      25                 :  * Diese Datei enthällt die Klasse MediaWikiInfo                                                                                                                                                                                                     
      26                 :  * @package eStudy.ExternalTools                                                                                                                                                                                                                      
      27                 :  * @version 1.0 13/10/05                                                                                                                                                                                                                              
      28                 :  * @author Christian Gerhardt <case42@gmx.net>                                                                                                                                                                                                        
      29                 :  */                                                                                                                                                                                                                                                   
      30               1 : if (!defined('PATH_TO_ROOT'))                                                                                                                                                                                                                         
      31               1 :     define("PATH_TO_ROOT", "../../");                                                                                                                                                                                                                 
      32                 :                                                                                                                                                                                                                                                       
      33                 : /**Die Basisklasse*/                                                                                                                                                                                                                                  
      34               1 : require_once ("class.toolinfo.inc.php");                                                                                                                                                                                                              
      35                 : //für passwörter                                                                                                                                                                                                                                    
      36               1 : require_once ("class.passwords.inc.php");                                                                                                                                                                                                             
      37               1 : define("WIKI_USER_TABLE", "user");                                                                                                                                                                                                                    
      38               1 : define("WIKI_USER_GROUP_TABLE", "user_groups");                                                                                                                                                                                                       
      39               1 : define("STUDENT_WIKI_USER_GROUP", "");                                                                                                                                                                                                                
      40               1 : define("TEACHER_WIKI_USER_GROUP", "sysop");                                                                                                                                                                                                           
      41               1 : define("ADMINISTRATOR_WIKI_USER_GROUP", "sysop");                                                                                                                                                                                                     
      42               1 : define("ASSISTENT_WIKI_USER_GROUP", "sysop");                                                                                                                                                                                                         
      43                 : /**                                                                                                                                                                                                                                                   
      44                 :  *                                                                                                                                                                                                                                                    
      45                 :  */                                                                                                                                                                                                                                                   
      46               1 : class MediaWikiInfo extends ToolInfo {                                                                                                                                                                                                                
      47                 :                                                                                                                                                                                                                                                       
      48                 :     public $wikiDefaultOptions = array (                                                                                                                                                                                                              
      49                 :         "quickbar" => 1,                                                                                                                                                                                                                              
      50                 :         "underline" => 2,                                                                                                                                                                                                                             
      51                 :         "cols" => 80,                                                                                                                                                                                                                                 
      52                 :         "rows" => 25,                                                                                                                                                                                                                                 
      53                 :         "searchlimit" => 20,                                                                                                                                                                                                                          
      54                 :         "contextlines" => 5,                                                                                                                                                                                                                          
      55                 :         "contextchars" => 50,                                                                                                                                                                                                                         
      56                 :         "skin" => "monobook",                                                                                                                                                                                                                         
      57                 :         "math" => 1,                                                                                                                                                                                                                                  
      58                 :         "rcdays" => 7,                                                                                                                                                                                                                                
      59                 :         "rclimit" => 50,                                                                                                                                                                                                                              
      60                 :         "highlightbroken" => 1,                                                                                                                                                                                                                       
      61                 :         "stubthreshold" => 0,                                                                                                                                                                                                                         
      62                 :         "previewontop" => 1,                                                                                                                                                                                                                          
      63                 :         "editsection" => 1,                                                                                                                                                                                                                           
      64                 :         "editsectiononrightclick" => 0,                                                                                                                                                                                                               
      65                 :         "showtoc" => 1,                                                                                                                                                                                                                               
      66                 :         "showtoolbar" => 1,                                                                                                                                                                                                                           
      67                 :         "date" => 0,                                                                                                                                                                                                                                  
      68                 :         "imagesize" => 2,                                                                                                                                                                                                                             
      69                 :         "thumbsize" => 2,                                                                                                                                                                                                                             
      70                 :         "rememberpassword" => 0,                                                                                                                                                                                                                      
      71                 :         "enotifwatchlistpages" => 0,                                                                                                                                                                                                                  
      72                 :         "enotifusertalkpages" => 1,                                                                                                                                                                                                                   
      73                 :         "enotifminoredits" => 0,                                                                                                                                                                                                                      
      74                 :         "enotifrevealaddr" => 0,                                                                                                                                                                                                                      
      75                 :         "shownumberswatching" => 1,                                                                                                                                                                                                                   
      76                 :         "fancysig" => 0,                                                                                                                                                                                                                              
      77                 :         "externaleditor" => 0,                                                                                                                                                                                                                        
      78                 :         "externaldiff" => 0,                                                                                                                                                                                                                          
      79                 :         "variant" => "en",                                                                                                                                                                                                                            
      80                 :         "language" => "en",                                                                                                                                                                                                                           
      81                 :         "searchNs0" => 1                                                                                                                                                                                                                              
      82                 :     );                                                                                                                                                                                                                                                
      83                 :                                                                                                                                                                                                                                                       
      84                 :     public function MediaWikiInfo($id, $image = null) {                                                                                                                                                                                               
      85               0 :         parent :: ToolInfo($image);                                                                                                                                                                                                                   
      86               0 :         $this->toolName = "Mediawiki 1.5";                                                                                                                                                                                                            
      87               0 :         $this->toolID = $id;                                                                                                                                                                                                                          
      88               0 :     }                                                                                                                                                                                                                                                 
      89                 :     public function encryptPassword($userid, $password) {                                                                                                                                                                                             
      90               0 :         return Passwords :: GenerateHash($password, $userid, HASH_MEDIAWIKI);                                                                                                                                                                         
      91                 :     }                                                                                                                                                                                                                                                 
      92                 :     public function getWikiUserData($wikiUserName) {                                                                                                                                                                                                  
      93               0 :         $query = "SELECT * FROM %s WHERE user_name='%s' LIMIT 1";                                                                                                                                                                                     
      94               0 :         $query = sprintf($query, WIKI_USER_TABLE, Data::toMysql(ucfirst($wikiUserName)));                                                                                                                                                             
      95               0 :         return $this->toolDB->get_row($query);                                                                                                                                                                                                        
      96                 :     }                                                                                                                                                                                                                                                 
      97                 :     public function createNewWikiUser($login, $password, $email, $realname, $usergroup) {                                                                                                                                                             
      98               0 :         global $EZSQL_ERROR;                                                                                                                                                                                                                          
      99               0 :         $errorCount = count($EZSQL_ERROR);                                                                                                                                                                                                            
     100               0 :         $options = array ();                                                                                                                                                                                                                          
     101               0 :         foreach ($this->wikiDefaultOptions as $key => $value) {                                                                                                                                                                                       
     102               0 :             array_push($options, $key . "=" . $value);                                                                                                                                                                                                
     103               0 :         }                                                                                                                                                                                                                                             
     104               0 :         $query = "INSERT INTO %s (user_name, user_real_name, user_password, user_newpassword, user_email,user_options, user_touched, user_token)";                                                                                                    
     105               0 :         $query .= "VALUES('%s','%s','%s','%s','%s','%s','%s','%s')";                                                                                                                                                                                  
     106               0 :         $query = sprintf($query, WIKI_USER_TABLE, Data::toMysql(ucfirst($login)), Data::toMysql($realname), "", "", Data::toMysql($email), implode("\n", $options), gmdate('YmdHis', time()), md5(microtime() . mt_rand(0, 0x7fffffff) . "blub" . 0));
     107               0 :         $this->toolDB->query($query);                                                                                                                                                                                                                 
     108               0 :         if ($errorCount != count($EZSQL_ERROR) || !isset ($this->toolDB->insert_id)) {                                                                                                                                                                
     109               0 :             return null;                                                                                                                                                                                                                              
     110                 :         } else {                                                                                                                                                                                                                                      
     111               0 :             $id = $this->toolDB->insert_id;                                                                                                                                                                                                           
     112               0 :             $query = "UPDATE %s SET user_password='%s' WHERE user_name='%s'";                                                                                                                                                                         
     113               0 :             $query = sprintf($query, WIKI_USER_TABLE, $this->encryptPassword($id, $password), Data::toMysql(ucfirst($login)));                                                                                                                        
     114               0 :             $this->toolDB->query($query);                                                                                                                                                                                                             
     115               0 :             if ($usergroup != STUDENT) {                                                                                                                                                                                                              
     116                 :                 switch ($usergroup) {                                                                                                                                                                                                                 
     117               0 :                     case DOZENT :                                                                                                                                                                                                                     
     118               0 :                         $group = TEACHER_WIKI_USER_GROUP;                                                                                                                                                                                             
     119               0 :                     case ADMIN :                                                                                                                                                                                                                      
     120               0 :                         $group = ADMINISTRATOR_WIKI_USER_GROUP;                                                                                                                                                                                       
     121               0 :                     case SEKRETARIAT :                                                                                                                                                                                                                
     122               0 :                         $group = ASSISTENT_WIKI_USER_GROUP;                                                                                                                                                                                           
     123               0 :                         break;                                                                                                                                                                                                                        
     124                 :                                                                                                                                                                                                                                                       
     125               0 :                     case STUDENT :                                                                                                                                                                                                                    
     126               0 :                     default :                                                                                                                                                                                                                         
     127               0 :                         $group = STUDENT_WIKI_USER_GROUP;                                                                                                                                                                                             
     128               0 :                 }                                                                                                                                                                                                                                     
     129               0 :                 $query = "INSERT INTO %s (ug_user, ug_group)";                                                                                                                                                                                        
     130               0 :                 $query .= "VALUES('%s','%s')";                                                                                                                                                                                                        
     131               0 :                 $query = sprintf($query, WIKI_USER_GROUP_TABLE, $id, $group);                                                                                                                                                                         
     132               0 :                 $this->toolDB->query($query);                                                                                                                                                                                                         
     133               0 :             }                                                                                                                                                                                                                                         
     134                 :         }                                                                                                                                                                                                                                             
     135               0 :         return $id;                                                                                                                                                                                                                                   
     136                 :     }                                                                                                                                                                                                                                                 
     137                 :     public function getRealName() {                                                                                                                                                                                                                   
     138               0 :         return utf8_encode($this->userData['Vorname'] . " " . $this->userData['Nachname']);                                                                                                                                                           
     139                 :     }                                                                                                                                                                                                                                                 
     140                 :     public function checkForUser() {                                                                                                                                                                                                                  
     141               0 :         $result = $this->getWikiUserData($this->getUserLogin());                                                                                                                                                                                      
     142               0 :         return !is_null($result);                                                                                                                                                                                                                     
     143                 :     }                                                                                                                                                                                                                                                 
     144                 :     public function getUserLogin() {                                                                                                                                                                                                                  
     145               0 :         return utf8_encode($this->userLogonData['login']);                                                                                                                                                                                            
     146                 :     }                                                                                                                                                                                                                                                 
     147                 :     public function insertNewUser() {                                                                                                                                                                                                                 
     148               0 :         $id = $this->createNewWikiUser($this->getUserLogin(), $this->userLogonData['password'], $this->userData['Email'], $this->getRealName(), $this->userData['Usergroup']);                                                                        
     149               0 :     }                                                                                                                                                                                                                                                 
     150                 :     public function removeUser($userID) {                                                                                                                                                                                                             
     151               0 :         $this->getLogonData();                                                                                                                                                                                                                        
     152               0 :         $this->connectToDB();                                                                                                                                                                                                                         
     153               0 :         $this->getUserLoginData($userID);                                                                                                                                                                                                             
     154               0 :         if ($this->checkForUser()) {                                                                                                                                                                                                                  
     155               0 :             $newLogin = $this->createLogoffLogin($this->getUserLogin());                                                                                                                                                                              
     156               0 :             $query = "UPDATE %s SET user_password='%s' WHERE user_name='%s'";                                                                                                                                                                         
     157               0 :             $query = sprintf($query, WIKI_USER_TABLE, md5(microtime()), $this->getUserLogin());                                                                                                                                                       
     158               0 :             $this->toolDB->query($query);                                                                                                                                                                                                             
     159               0 :             $querys[] = "update user set user_name='%s' where user_name='%s';";                                                                                                                                                                       
     160               0 :             $querys[] = "update user_newtalk set user_ip='%s' where user_ip='%s';";                                                                                                                                                                   
     161                 :             //$querys[] = "update cur set cur_user_text='%s' where cur_user_text='%s';";                                                                                                                                                              
     162                 :             //$querys[] = "update old set old_user_text='%s' where old_user_text='%s';";                                                                                                                                                              
     163               0 :             $querys[] = "update archive set ar_user_text='%s' where ar_user_text='%s';";                                                                                                                                                              
     164               0 :             $querys[] = "update ipblocks set ipb_address='%s' where ipb_address='%s';";                                                                                                                                                               
     165               0 :             $querys[] = "update image set img_user_text='%s' where img_user_text='%s';";                                                                                                                                                              
     166               0 :             $querys[] = "update oldimage set oi_user_text='%s' where oi_user_text='%s';";                                                                                                                                                             
     167               0 :             $querys[] = "update recentchanges set rc_user_text='%s' where rc_user_text='%s';";                                                                                                                                                        
     168               0 :             foreach ($querys as $query) {                                                                                                                                                                                                             
     169               0 :                 $this->toolDB->query(sprintf($query, $newLogin, $this->getUserLogin()));                                                                                                                                                              
     170               0 :             }                                                                                                                                                                                                                                         
     171               0 :         }                                                                                                                                                                                                                                             
     172               0 :     }                                                                                                                                                                                                                                                 
     173                 :     public function updateLogin($oldLogin, $newLogin, $password) {                                                                                                                                                                                    
     174               0 :         global $EZSQL_ERROR;                                                                                                                                                                                                                          
     175               0 :         $oldLogin = utf8_encode($oldLogin);                                                                                                                                                                                                           
     176               0 :         $newLogin = utf8_encode($newLogin);                                                                                                                                                                                                           
     177               0 :         if ($this->checkForUser()) {                                                                                                                                                                                                                  
     178               0 :             $query = "SELECT user_id FROM %s WHERE user_name='%s'";                                                                                                                                                                                   
     179               0 :             $query = sprintf($query, WIKI_USER_TABLE, Data::toMysql(ucfirst($oldLogin)));                                                                                                                                                             
     180               0 :             $id = $this->toolDB->get_var($query);                                                                                                                                                                                                     
     181               0 :             $p = $this->encryptPassword($id, $password);                                                                                                                                                                                              
     182               0 :             $query = "UPDATE %s SET user_name='%s', user_password='%s' WHERE user_name='%s' ";                                                                                                                                                        
     183               0 :             $query = sprintf($query, WIKI_USER_TABLE, $newLogin, $p, Data::toMysql(ucfirst($oldLogin)));                                                                                                                                              
     184               0 :             $this->toolDB->query($query);                                                                                                                                                                                                             
     185                 :             if ($EZSQL_ERROR)                                                                                                                                                                                                                         
     186               0 :                 return false;                                                                                                                                                                                                                         
     187               0 :         } else {                                                                                                                                                                                                                                      
     188               0 :             $this->insertNewUser();                                                                                                                                                                                                                   
     189                 :         }                                                                                                                                                                                                                                             
     190               0 :         return true;                                                                                                                                                                                                                                  
     191                 :     }                                                                                                                                                                                                                                                 
     192                 :     public function createLogoffLogin($login) {                                                                                                                                                                                                       
     193               0 :         $query = "SELECT * FROM %s WHERE user_name='%s'";                                                                                                                                                                                             
     194               0 :         $query = sprintf($query, WIKI_USER_TABLE, "%s");                                                                                                                                                                                              
     195               0 :         $result = true;                                                                                                                                                                                                                               
     196               0 :         while ($result) {                                                                                                                                                                                                                             
     197               0 :             $newLogin = sprintf("%s(%s)", $login, date("d-m-y,H:i:s"));                                                                                                                                                                               
     198               0 :             $result = $this->toolDB->get_row(sprintf($query, $newLogin));                                                                                                                                                                             
     199               0 :         }                                                                                                                                                                                                                                             
     200               0 :         return $newLogin;                                                                                                                                                                                                                             
     201                 :     }                                                                                                                                                                                                                                                 
     202                 :     public function showOptionsDialog($hiddenVars) {                                                                                                                                                                                                  
     203               0 :         return true;                                                                                                                                                                                                                                  
     204                 :     }                                                                                                                                                                                                                                                 
     205                 :     public function optionsHandler($event) {                                                                                                                                                                                                          
     206               0 :     }                                                                                                                                                                                                                                                 
     207                 : }                                                                                                                                                                                                                                                     
     208                 : ?>                                                                                                                                                                                                                                                    

Generated by PHPUnit 3.2.21 and Xdebug 2.0.4 at Sat Nov 7 22:04:08 CET 2009.